<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>编辑用户</h4>
		<form class="form-horizontal" id="myform">
			<div class="form-group">
				<label for="username" class="col-sm-2 control-label">用户名</label>
				<div class="col-sm-5">
					<input type="text" name="username" class="form-control" id="username" placeholder="用户名" value="<{$userinfo['username']}>" readonly>
				</div>
			</div>
			
			<div class="form-group">
				<label for="password" class="col-sm-2 control-label">密码</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="password" id="password" placeholder="密码">
				</div>
			</div>
			
			<div class="form-group">
				<label for="nickname" class="col-sm-2 control-label">真实姓名</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="nickname" id="nickname" value="<{$userinfo['nickname']}>" placeholder="真实姓名">
				</div>
			</div>
			
			<div class="form-group">
				<label for="email" class="col-sm-2 control-label">电子邮箱</label>
				<div class="col-sm-5">
					<input type="text" class="form-control" name="email" id="email" value="<{$userinfo['email']}>" placeholder="电子邮箱">
				</div>
			</div>
		
			<div class="form-group">
				<label class="col-sm-2 control-label">角色</label>
				<div class="col-sm-5">
					<select name="role" class="form-control">
						<option value="0">-请选择-</option>
						<foreach name="role" item="vo">
							<option value="<{$vo['id']}>"  <if condition="$userinfo['role'] eq $vo['id']">selected</if>><{$vo['name']}></option>
						</foreach>
					</select>
				</div>
			</div>
			
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="hidden" name="uid" value="<{$userinfo['id']}>" />
					<button type="submit" class="btn btn-default col-sm-2">保存</button>
				</div>
			</div>
		</form>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/validate/messages_zh.js"></script>
<script>
$(function(){
	
	$('#password').on('click', function(){
	    var that = this;
	    layer.tips('密码长度由6-20字符组成,留空表示不修改密码。', that, {
		    tips: [2, '#3595CC'],
		});
	});
	
	$("#myform").validate({
		rules: {
            password: {
                rangelength:[6,20]
            },
            email : {
            	email:true
            }
		},
		messages: {
			email : {
				email:"电子邮箱格式不正确",
			}
		},
		submitHandler : function(form){
			var ajaxUrl = "<{:U('Admin/Admin/do_userEdit')}>";
			 $.post(ajaxUrl,$(form).serialize(),function(r){
    			if (r.error == 1){
    				layer.alert(r.errmsg,{icon: 2});
    			}else{
    				layer.alert(r.errmsg,{icon: 1},function(){
    					window.location.href = "<{:U('Admin/Admin/userList',array('k'=>5,'sk'=>0))}>";
    				});
    			}
    			return false;
    		});
        	return false
		}
	});
});
</script>

<include file="Public/footer" /> 